####################################################################
####################################################################
####Non-state Atrocities in Capital Cities - Mechanism 1 (Maps) ####
####################################################################
####################################################################
library(interplot)
library(ggplot2)
library(ggthemes)
library(maps)
library(maptools)
library(ggmap)
library(mapdata)
library(RgoogleMaps)

# Set working library
setwd("~/Data/Mechanism 1/")

##############
###Pakistan###
##############
## Read in cities and atrocity location data
#Insurgent atrocities
pitf.pak.col <- read.csv("pakinc.csv")
# Cities
cities.pak <- read.csv("pakcit.csv")
## Subset by indicator for capitals and other cities for plotting
#Capitals
cap.pak.dat <- subset(cities.pak, capital==1)
#Other cities
cities.pak <- subset(cities.pak, capital==0)

##Plot the maps
#Create map
pakmap <- ggmap(get_map(location = 'Pakistan',  color = "bw", zoom = 5)) +
  geom_point(data=pitf.pak.col, aes(x=longitude, y=latitude, size=event),shape=20, color="red", alpha=0.7) +
  scale_size_area(max_size=12, name = "N Atrocities", guide = FALSE) + 
  geom_point(data=cities.pak, aes(x=lng, y=lat, size=cit_ind),shape=15, color="green", alpha=0.7) +
  geom_point(data=cap.pak.dat, aes(x=lng, y=lat, size=cit_ind),shape=17, color="blue", alpha=0.7) + 
  labs(x="",y="",title="") +
  scale_x_continuous(limits=c(61.5,77)) +
  scale_y_continuous(limits=c(24.2,36.2))

#Export to pdf
pdf("pakcitmap.pdf")
pakmap
dev.off()


##########
###Iraq###
##########
## Read in cities and atrocity location data
#Insurgent atrocities
pitf.irq.col <- read.csv("irqinc.csv")
#Cities
cities.irq <- read.csv("irqcit.csv")
## Subset by indicator for capitals and other cities for plotting
#Capitals
cap.irq.dat <- subset(cities.irq, capital==1)
#Other cities
cities.irq <- subset(cities.irq, capital==0)

##Plot the maps
#Create map
irqmap <- ggmap(get_map(location = 'Iraq',  color = "bw", zoom = 5)) +
  geom_point(data=pitf.irq.col, aes(x=longitude, y=latitude, size=event),shape=20, color="red", alpha=0.7) +
  scale_size_area(max_size=30, name = "N Atrocities", guide = FALSE) + 
  geom_point(data=cities.irq, aes(x=lng, y=lat, size=cit_ind),shape=15, color="green", alpha=0.7) +
  geom_point(data=cap.irq.dat, aes(x=lng, y=lat, size=cit_ind),shape=17, color="blue", alpha=0.7) +
  labs(x="",y="",title="") +
  scale_x_continuous(limits=c(39,48)) +
  scale_y_continuous(limits=c(29.3,37))

#Export to pdf
pdf("irqcitmap.pdf")
irqmap
dev.off()

#################
###Afghanistan###
#################
## Read in cities and atrocity location data
#Insurgent atrocities
pitf.afg.col <- read.csv("afginc.csv")
#Cities
cities.afg <- read.csv("afgcit.csv")
## Subset by indicator for capitals and other cities for plotting
#Capitals
cap.afg.dat <- subset(cities.afg, capital==1)
#Other cities
cities.afg <- subset(cities.afg, capital==0)

##Plot the maps
#Create map
afgmap <- ggmap(get_map(location = 'Afghanistan',  color = "bw", zoom = 5)) +
  geom_point(data=pitf.afg.col, aes(x=longitude, y=latitude, size=event),shape=20, color="red", alpha=0.7) +
  scale_size_area(max_size=10, name = "N Atrocities", guide = FALSE) + 
  geom_point(data=cities.afg, aes(x=lng, y=lat, size=cit_ind),shape=15, color="green", alpha=0.7) +
  geom_point(data=cap.afg.dat, aes(x=lng, y=lat, size=cit_ind),shape=17, color="blue", alpha=0.7) +
  labs(x="",y="",title="") +
  scale_x_continuous(limits=c(61,73)) +
  scale_y_continuous(limits=c(29,38))

#Export to pdf
pdf("afgcitmap.pdf")
afgmap
dev.off()


############
###India###
###########
## Read in cities and atrocity location data
#Insurgent atrocities
pitf.ind.col <- read.csv("indinc.csv")
#Cities
cities.ind <- read.csv("indcit.csv")
## Subset by indicator for capitals and other cities for plotting
#Capitals
cap.ind.dat <- subset(cities.ind, capital==1)
#Other cities
cities.ind <- subset(cities.ind, capital==0)

##Plot the maps
#Create map
indmap <- ggmap(get_map(location = 'India',  color = "bw", zoom = 4)) +
  geom_point(data=pitf.ind.col, aes(x=longitude, y=latitude, size=event),shape=20, color="red", alpha=0.7) +
  scale_size_area(max_size=10, name = "N Atrocities", guide = FALSE) + 
  geom_point(data=cities.ind, aes(x=lng, y=lat, size=cit_ind),shape=15, color="green", alpha=0.7) +
  geom_point(data=cap.ind.dat, aes(x=lng, y=lat, size=cit_ind),shape=17, color="blue", alpha=0.7) +
  labs(x="",y="",title="") +
  scale_x_continuous(limits=c(69,94))+
  scale_y_continuous(limits=c(7,34))

#Export to pdf
pdf("indcitmap.pdf")
indmap
dev.off()
